package com.zrrd.io.bufferedStream;

import java.io.BufferedReader;
import java.io.FileReader;

/**
 * @author WanJl
 * @version 1.0
 * @title BufferedReaderDemo01
 * @description 缓冲字符输入流  读
 * @create 2023/10/14 19:06
 */
public class BufferedReaderDemo01 {

    public String read(String fileName) throws Exception {
        FileReader reader = new FileReader(fileName);
        BufferedReader br = new BufferedReader(reader);
        //循环读取数据
        String line;
        //定义一个字符串对象(可变长度的字符串)。
        StringBuilder stringBuilder = new StringBuilder();

        while ((line= br.readLine())!=null){
            stringBuilder.append(line);
        }
        String s = stringBuilder.toString();
        br.close();
        reader.close();
        return s;
    }

    //你在模拟用户的操作。
    public static void main(String[] args) throws Exception {
        BufferedReaderDemo01 readerDemo01 = new BufferedReaderDemo01();
        String s = readerDemo01.read("D:/张三.txt");
        System.out.println(s);
    }

}
